import './WijmoComModifyStatus.scss'
import { useState } from 'react'
import { useRequest } from 'alova/client'
import { Input, Button, Radio, Divider } from 'antd'

import { Http } from '../../API'

const { TextArea } = Input

const urlMapping = {
    1: 'posBuyReturnInfoUpdateStatus',
    2: 'posBuyReturnInfoUpdateDataStatus',
}

const radioOptions = {
    1: [
        { value: '待发货', label: '待发货' },
        { value: '已收货', label: '已收货' },
        { value: '已发货', label: '已发货' },
        { value: '作废', label: '作废' },
    ],
    2: [
        { value: '退货中', label: '退货中' },
        { value: '完成退货', label: '完成退货' },
        { value: '作废', label: '作废' },
    ]
}

const WijmoComModifyStatus = ({ data, Off, ModalEvent }) => {
    const { uuid, orderMasterUuid, status, remark, classData } = data
    const [Status, setStatus] = useState(status)
    const [Remark, setRemark] = useState(remark)
    const [loading, setLoading] = useState(false)

    const { send } = useRequest(params => Http({ url: urlMapping[classData], params }), { immediate: false })

    const onSubmit = () => {
        setLoading(true)
        send({ uuid: classData === 1 ? orderMasterUuid : uuid, Status, Remark }).then(() => {
            ModalEvent.emit({ type: 'Refresh' })
            Off()
        })
    }

    return (
        <div className='WijmoComModifyStatus'>
            <Divider orientation="left">订单状态</Divider>
            <Radio.Group
                options={radioOptions[classData]}
                style={{ width: '100%' }}
                defaultValue={Status}
                buttonStyle="solid"
                optionType="button"
                onChange={e => setStatus(e.target.value)}
            />

            <Divider orientation="left">备注信息</Divider>
            <TextArea rows={4} defaultValue={Remark} onChange={e => setRemark(e.target.value)} />
            <div style={{ height: 16 }} />
            <Button type="primary" size='large' onClick={onSubmit} loading={loading}>提交</Button>
        </div>
    );
};

export default WijmoComModifyStatus;